import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint'
import { baseCfg, pluginCfg } from './vconfig'

export default async ({ mode }) => {
  const { VITE_BASE_URL } = loadEnv(mode, process.cwd())
  return defineConfig({
    ...baseCfg({ VITE_BASE_URL }),
    plugins: [
      vue(),
      process.env.NODE_ENV === 'development' && eslintPlugin({
        include: [ 'src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue' ],
        cache: false
      }),
      ...await pluginCfg({ VITE_BASE_URL }) ]
  })
}
